from fastapi import APIRouter
from tortoise.expressions import F

from db.models.warehouse import Warehouse
from ApiResponse import ApiResponse, DataDict
from typing import List

# 创建路由
warehouse_router = APIRouter()


@warehouse_router.get('/dict', summary="仓库字典")
async def get_warehouse_list() -> ApiResponse[List[DataDict]]:
    """
    获取仓库列表接口
    返回所有未删除仓库的 whid 和 whname
    """
    # 查询所有未删除的仓库
    result = await Warehouse.filter(del_flag__not="2").annotate(
        label=F("whname"),
        value=F("whid")
    ).values("value", "label")
    return ApiResponse.ok(data=result, msg="仓库列表查询成功")
